# -*- coding:utf-8 -*-

'''
dp[i][j]=True　　　　　　if (i == j)
dp[i][j]=(s[i]==s[j]) 　　　　　　　　　　if (j - i == 1)
dp[i][j]=(s[i]==s[j]) && dp[i+1][j−1] 　if (j - i >= 2)

'''


class Palindrome:
    def getLongestPalindrome(self, s, a):
        # write code here
        # maxlen = 1
        # f = [[False] * a for _ in range(a)]
        # for j in range(a):
        #     # 保证i是子串起始，j是子串末尾  f[i+1][j-1]
        #     for i in range(j):
        #         # l = s[i:j]
        #         f[i][j] = s[i]==s[j] and (j-i<2 or f[i+1][j-1])
        #         # ss=f[i][j]
        #         if f[i][j] and maxlen < j-i+1:
        #             maxlen=j-i+1
        #     f[j][j] = True
        # return maxlen



# 方法2
        maxlen = 1
        for i in range(a):
            '''
                两个if的区别就是 最后那个是个相等
            '''
            if i-maxlen>=1 and (s[i-maxlen-1:i+1]==s[i-maxlen-1:i+1][::-1]):
                maxlen+=2
                continue
            if i-maxlen>=0 and (s[i-maxlen:i+1]==s[i-maxlen:i+1][::-1]):
                maxlen+=1
        return maxlen


a = "baabccc"
s = Palindrome()
m = s.getLongestPalindrome(a,7)
print(m)
